<?php
/**
 * Created by PhpStorm.
 * User: cjm
 * Date: 2018/10/7
 * Time: 19:21
 */

namespace App\Transformers;



use App\Models\Good;
use App\Models\GoodCategory;
use League\Fractal\TransformerAbstract;

class CategoryTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['good'];

    public function transform(GoodCategory $category){
        return [
            'id' => $category->id,
            'cname' => $category->cname,
            'parent_id' => $category->parent_id,
            'created_at' => $category->created_at->toDateTimeString(),
            'updated_at' => $category->updated_at->toDateTimeString(),
            'lev' => $category->lev
        ];
    }

    public function includeGood(GoodCategory $category){
        return $this->collection($category->goods,new GoodslistTransformer());
    }
}